package Math;

import java.util.HashMap;
import java.util.Map;

public class _781_RabbitsinForest {
    //solve 300 problem record.
    public int numRabbits(int[] answers) {
        if(answers.length==0) return 0;
        Map<Integer, Integer> rabbits = new HashMap<>();
        for (int answer : answers) {
            rabbits.put(answer, rabbits.getOrDefault(answer, 0) + 1);
        }
        int count = 0;
        for (Map.Entry<Integer, Integer> rabbit : rabbits.entrySet()) {
                int rSum = rabbit.getKey() + 1;
                count += (((rabbit.getValue() - 1) / rSum) + 1) * rSum;
        }
        return count;
    }
}
